<template>
  <div class="container" ref="mainCon">
    <topTitle
      :titleText="titleText"
      :back="back"
      :tipStatus="`check`"
      @gobackTriser="goBack"
      ><template #check> 待审核 </template></topTitle
    >
    <div class="mainCon"></div>
  </div>
</template>
<script>
export default {
  name: 'kmAddCase',
  data() {
    const checkPhoneOrTel = (rule, value, callback) => {
      let flag1 = 1
      let flag2 = 1
      if (!/^1[3456789]\d{9}$/.test(value)) {
        flag1 = 2
      }
      if (!/^(\d{3,4}-)?\d{7,8}$/.test(value)) {
        flag2 = 2
      }
      if (value) {
        if (flag1 == 2 && flag2 == 2) {
          callback(new Error('请输入正确的手机号或者座机号码'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    //缴纳凭证验证
    var checkPayUploadFile = (rule, value, callback) => {
      if (this.uploadPayFile.length === 0) {
        return callback(new Error('案件材料不能为空'))
      } else {
        callback()
      }
    }
    return {
      titleText: '添加案件',
      back: true,
      formData: {
        casenum: '',
        casename: '',
        operator: '',
        phone: '',
        upLoadFileAcc: [],
      },
      isSaveLoading: false,
      uploadPayFile: [],
      formRules: {
        casename: [
          { required: true, message: '请输入案件名称', trigger: 'blur' },
          {
            required: true,
            min: 1,
            max: 60,
            message: '请输入1-60个字符',
            trigger: 'blur',
          },
        ],
        operator: [
          {
            required: true,
            message: '请输入案件经办人员姓名',
            trigger: 'blur',
          },
          {
            required: true,
            min: 1,
            max: 60,
            message: '请输入1-60个字符',
            trigger: 'blur',
          },
        ],
        phone: [
          { required: true, message: '请输入联系方式', trigger: 'blur' },
          { required: true, validator: checkPhoneOrTel, trigger: 'blur' },
        ],
        upLoadFileAcc: [
          {
            required: true,
            // message: "缴纳凭证不能为空",
            validator: checkPayUploadFile,
            trigger: 'change',
          },
        ],
      },

      limitationFactor: {
        uploadAnnexUrl: 'api-f/files/upload', //自定义上传文件接口地址
        upLoadFileLength: 20, //自定义上传文件最大数量设置
        fileSize: 50, //自定义上传文件最大设置
        formatType: 'typeFour', //自定义上传格式校验类型
        messagetip:
          '要求格式为png，jpg，jpeg，doc，docx，xls，xlsx，pdf格式，附件大小不超过50M', //自定义报错提示语
        fileId: 'salaryExcel', //自定义id解决一个页面包含多个上传附件
        uploadFormId: 'salaryExcelForm', //自定义id解决一个页面包含多个上传附件
        methodTip:
          '请上传案件材料，附件格式支持png，jpg，jpeg，doc，docx，xls，xlsx，pdf，最多上传20个附件', //自定义上传文件提示
        uploadBtnType: 'typeOne', //自定义上传按钮类型
        messageFileSizetip: '最多能上传50M以内的附件',
      },
    }
  },
  methods: {
    goBack() {},
    getFile(val) {
      this.uploadPayFile = val
    },
    saveToDetail() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
        } else {
          return false
        }
      })
    },
  },
}
</script>
<style lang="less" scoped></style>
